<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
       * {
        margin: 0%;
        padding: 0%;
       }
        img {
            width: 400px;
            height: 300px;
        }
        body {
            background: url(./images/1.jpg) no-repeat top center;
            /* 铺满整个屏幕 */
            background-size: 100% 100%;
			background-attachment: fixed;
        }
        ul {
            overflow: hidden;
            list-style: none;
            padding: 300px 1em 200px 300px;
        }
        li {
             /* 去掉前面的小圆点 */
            list-style-type: none;
            width: 100%;
            cursor: pointer;
            /* 横向排列 */
            display: inline;
        }

    </style>
</head>
<body>
   
        <div>
            <ul>
                <li> <img id="1" src="./images/1.jpg" alt=""></li>
                <li> <img id="2" src="./images/2.jpg" alt=""></li>
                <li> <img id="3" src="./images/3.jpg" alt=""></li>
                <li> <img id="4" src="./images/4.jpg" alt=""></li>
            </ul>
    </div>
    <script>
        const li = document.querySelectorAll('li');
        for(let i = 0;i < li.length;++i){
            li[i].addEventListener('click',()=>{
                const img = document.querySelector(`ul li:nth-child(${i+1}) img`);
                console.log(img);
                document.body.style.backgroundImage = `url(${img.src})`;
            });
        }
    </script>
</body>
</html>

